function getLocation(type){
    wx.ready(function () {
        wx.getLocation({
            success: function (res) {
                longitude = res.longitude;
                latitude = res.latitude;
                $('#lat').val(latitude);
                $('#lng').val(longitude);
                var latlon = latitude+','+longitude;
                //baidu
                var url = 'http://api.map.baidu.com/geocoder/v2/?ak=dwbzRtGa41pgkcduhiEZGjXpxmFtmGcf&callback=renderReverse&location='+latlon+'&output=json&pois=0';
                $.ajax({
                    type: "GET",
                    dataType: "jsonp",
                    url: url,
                    beforeSend: function(){
                        myAlert('百度地图正在定位...');
                    },
                    success: function (json) {
                        if(json.status==0){
                            $('#address').val(json.result.formatted_address);
                           if(type){
                               $('#province').val(json.result.addressComponent.province);
                               getCity(json.result.addressComponent.city);
                               getArea(json.result.addressComponent.district);
                           }
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        myAlert(latlon+"地址位置获取失败");
                    }
                });
            },
            cancel: function (res) {
                alert("用户拒绝授权获取地理位置");
            }
        });
    });
}
